package ab.mes.service.impl;

import ab.mes.entity.Bin;
import ab.mes.entity.FinishedProductBin;
import ab.mes.mapper.BinMapper;
import ab.mes.mapper.FinishedProductBinMapper;
import ab.mes.service.FinishedProductBinService;
import ab.mes.tools.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class FinishedProductBinServiceImpl implements FinishedProductBinService {
    @Autowired
    private FinishedProductBinMapper finishedProductBinMapper;

    //获取库位信息
    public Result getFinishedProductBin(){
        Result result = new Result();
        result.getMap().put("finished_product_bin",finishedProductBinMapper.getFinishedProductBin());
        return result;
    }

    //根据库位编号查询物料库位信息
    public Result getFinishedProductBinById(String Id){
        Result result = new Result();
        result.getMap().put("finished_product_bin",finishedProductBinMapper.getFinishedProductBinById(Id));
        return result;
    }

    //停启用物料库位
    public void updateStateById(String Id){
        FinishedProductBin bin = (FinishedProductBin)getFinishedProductBinById(Id).getMap().get("finished_product_bin");
        bin.setBinState(!bin.getBinState());
        finishedProductBinMapper.updateStateById(Id,bin.getBinState());
    }

    //新增库位
    public Result insertFinishedProductBin(FinishedProductBin finishedProductBin){
        Result result = new Result();
        result.getMap().put("finished_product_bin",finishedProductBinMapper.editFinishedProductBin(finishedProductBin));
        return result;
    }

    //编辑库位
    public Result editFinishedProductBin(FinishedProductBin finishedProductBin){
        Result result = new Result();
        result.getMap().put("finished_product_bin",finishedProductBinMapper.insertFinishedProductBin(finishedProductBin));
        return result;
    }
}
